﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;

namespace CPPEI.PM.Service.Model.Repository
{
    public class WorkStageItemRefRepository
    {
        private DbContext _dbContext;
        public WorkStageItemRefRepository(DbContext dbContext)
        {
            _dbContext = dbContext;
        }

        public WorkStageItemRef Get(Guid workSheetId, Guid workStageItemId)
        {
            return _dbContext.Set<WorkStageItemRef>().SingleOrDefault(p => p.WorkSheetId == workSheetId && p.WorkStageItemId == workStageItemId);
        }

        public List<WorkStageItemRef> GetByParent(Guid workSheetId, Guid workStageId, Guid parentWorkStageItemId)
        {
            return _dbContext.Set<WorkStageItemRef>().Where(p => p.WorkSheetId == workSheetId
                && p.WorkStageId == workStageId
                && p.ParentWorkStageItemId == parentWorkStageItemId).ToList();
        }

        public void Create(WorkStageItemRef workStageItemRef)
        {
            _dbContext.Set<WorkStageItemRef>().Add(workStageItemRef);
        }
    }
}
